﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Add-PromotionCode.aspx.cs" Inherits="Add_PromotionCode" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
    <link href="css/style-metro.css" rel="stylesheet" type="text/css" />
    <style>
        label
        {
            display: inline !important;
            padding-left: 2px;
            padding-right: 10px;
            vertical-align: middle;
        }
        .radio input[type="radio"], .checkbox input[type="checkbox"]
        {
            float: left;
            margin-left: 0px !important;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <div class="row-fluid">
        <div class="span12">
            <%--   <form action="#" class="form-horizontal">
            </form>--%>
            <div class="portlet box yellow">
                <div class="portlet-title">
                    <div class="caption">
                        <asp:Label runat="server" ID="lblHeader" Text="Add Promotion Code"></asp:Label></div>
                </div>
                <div class="portlet-body form">
                    <div id="divMessage" runat="server" class="generalMessage">
                    </div>
                    <div class="row-fluid">
                        <div class="span6 ">
                            <div class="control-group" id="divSubscription">
                                <label class="control-label">
                                    Select Subscription</label>
                                <div class="controls">
                                    <asp:DropDownList runat="server" ID="drpSubscription" CssClass="span12 select2_category subscription"
                                        DataValueField="Id" DataTextField="PlanName">
                                    </asp:DropDownList>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row-fluid">
                        <div class="span6 ">
                            <div class="control-group" id="divPromotionCode">
                                <label class="control-label">
                                    Promotion Code</label>
                                <div class="controls">
                                    <asp:TextBox runat="server" ID="txtPromotionCode" Enabled="false" CssClass="span12  promotionCode"></asp:TextBox>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row-fluid">
                        <div class="span6 ">
                            <div class="control-group" id="divMainType">
                                <label class="control-label">
                                    Discount On</label>
                                <div class="controls">
                                    <asp:RadioButtonList runat="server" ID="rbMainType" RepeatDirection="Horizontal"
                                        CssClass="radioMainType" onclick="MainTypeChanged();">
                                        <asp:ListItem Value="1"> Amount</asp:ListItem>
                                        <asp:ListItem Value="2"> Duration</asp:ListItem>
                                    </asp:RadioButtonList>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row-fluid" id="divType" style="display: none;">
                        <div class="span6 ">
                            <div class="control-group" id="divTypeInfo">
                                <label class="control-label">
                                    Type</label>
                                <div class="controls">
                                    <asp:RadioButtonList runat="server" ID="rbType" RepeatDirection="Horizontal" CssClass="radioType"
                                        onclick="TypeChanged();">
                                        <asp:ListItem Value="1">Discount Rate</asp:ListItem>
                                        <asp:ListItem Value="2">Amount</asp:ListItem>
                                    </asp:RadioButtonList>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row-fluid" id="divValue" style="display: none;">
                        <div class="span6 ">
                            <div class="control-group" id="divAmount">
                                <label class="control-label lblHeading">
                                    Month
                                </label>
                              
                                <div class="controls">
                                    <asp:TextBox runat="server" onblur="CheckValue();" ID="txtDiscount" CssClass="span12  amount"
                                        onkeypress="return allowPositiveNo(event);"></asp:TextBox>
                                          <label  class="msg">Hello jay jalaram</label>

                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row-fluid">
                        <div class="span6 ">
                            <div class="control-group" id="divStartDate">
                                <label class="control-label">
                                    <span class="Required">*</span>Start Date</label>
                                <div class="controls">
                                    <asp:TextBox runat="server" ID="txtStartDate" CssClass="m-wrap span12 startDate"></asp:TextBox>
                                    <asp:CalendarExtender runat="server" ID="ceStartdate" Format="dd/MM/yyyy" TargetControlID="txtStartDate"></asp:CalendarExtender>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row-fluid">
                        <div class="span6 ">
                            <div class="control-group" id="divExpiryDate">
                                <label class="control-label">
                                    <span class="Required">*</span>Expiry Date</label>
                                <div class="controls">
                                    <asp:TextBox runat="server" ID="txtExpiryDate" CssClass="m-wrap span12 expiryDate"></asp:TextBox>
                                    <asp:CalendarExtender runat="server" ID="ceExpirydate" TargetControlID="txtExpiryDate" Format="dd/MM/yyyy"></asp:CalendarExtender>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row-fluid">
                        <div class="span6 ">
                            <div class="control-group" id="divAllowUser">
                                <label class="control-label">
                                    Allow User</label>
                                <div class="controls">
                                    <asp:TextBox runat="server" ID="txtAllowUser" CssClass="span12  allowUser" onkeypress="return allowPositiveNo(event);"
                                        MaxLength="2"></asp:TextBox>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-actions">
                        <asp:Button ID="btnSave" runat="server" Text="Save" CssClass="btn blue frmValidation"
                            OnClick="Save" />
                        <asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="btn" PostBackUrl="~/PromotionCode-List.aspx" />
                    </div>
                </div>
            </div>
        </div>
        <!-- END PAGE CONTENT-->
    </div>
    <script type="text/javascript">
        var msg = "Please check your validations in red.";
        $('.frmValidation').click(function () {

            var isError = "false";

            var subId = $('#<%= drpSubscription.ClientID %>').val();

            if (subId == "0" || subId == "") {
                $('.subscription').closest("#divSubscription").addClass("error");
                isError = "true";
            }
            else {
                $('.subscription').closest("#divSubscription").removeClass("error");
            }

            if ($('.promotionCode').val() == "") {
                $('.promotionCode').closest("div #divPromotionCode").addClass("error");
                isError = "true";
            }
            else {
                $('.promotionCode').closest("div #divPromotionCode").removeClass("error");

            }


            if ($('.allowUser').val() != "") {
                var data = $('.allowUser').val();
                var r = checkNumeric(data);

                if (r == false) {
                    $('.allowUser').closest("div #divAllowUser").addClass("error");
                    isError = "true";
                }
                else {
                    $('.allowUser').closest("div #divAllowUser").removeClass("error");
                }
            }
            else
                $('.allowUser').closest("div #divAllowUser").removeClass("error");



            if ($('.startDate').val() == "") {
                $('.startDate').closest("div #divStartDate").addClass("error");
                isError = "true";
            }
            else {
                $('.startDate').closest("div #divStartDate").removeClass("error");

            }
            if ($('.expiryDate').val() == "") {
                $('.expiryDate').closest("div #divExpiryDate").addClass("error");
                isError = "true";
            }
            else {
                $('.expiryDate').closest("div #divExpiryDate").removeClass("error");

            }
            var isvalidAmount = true;

            //value can not be grater then 3 in Month
            var selectedMain = $('#<%=rbMainType.ClientID %> input:checked').val();
            if (selectedMain == "2") {
                if ($('.amount').val() > 4) {
                    isvalidAmount = false;
                    isError = "true";
                }

            }
            //value can not be grater then 50 in discount
            var selected = $('#<%=rbType.ClientID %> input:checked').val();
            if (selected == "1") {
                if ($('.amount').val() > 50) {
                    isvalidAmount = false;
                }
            }
            //value can not be empty
            if ($('.amount').val() == "") {
                isvalidAmount = false;
            }
            else {
                var data = $('.amount').val();
                //value must be numeric
                var r = checkNumeric(data);
                if (r == false) {
                    isvalidAmount = false;
                }
            }
            if (isvalidAmount == false) {

                $('.amount').closest("div #divAmount").addClass("error");
                isvalidAmount = false;
            }
            else
                $('.amount').closest("div #divAmount").removeClass("error");

            if ($('#<%=rbMainType.ClientID %> input:checked').val() != "1" && $('#<%=rbMainType.ClientID %> input:checked').val() != "2") {

                $('.radioMainType').closest("div #divMainType").addClass("error");
                isError = "true";
            }
            else
                $('.radioMainType').closest("div #divMainType").removeClass("error");


            if ($('#<%=rbType.ClientID %> input:checked').val() != "1" && $('#<%=rbType.ClientID %> input:checked').val() != "2" && selectedMain == "1") {
                $('.radioType').closest("div #divTypeInfo").addClass("error");
                isError = "true";
            }
            else
                $('.radioType').closest("div #divTypeInfo").removeClass("error");


            if (isError == "true") {
                $(".generalMessage").html("<strong>Error!</strong> " + msg);
                $(".generalMessage").addClass("alert alert-danger");
                return false;
            }
        });
        function checkNumeric(data) {
            var len = data.length;
            var c;
            for (var i = 0; i < len; i++) {
                c = data.charAt(i).charCodeAt(0);
                if (c < 48 || c > 57) {
                    isError = "true";
                    return false;
                    break;
                }
                else {
                    return true;
                }
            }
        }
        function allowPositiveNo(evt) {

            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57))
                return false;
            return true;
        }
        function CheckValue() {

        }
    </script>
    <script>
     <script type="text/javascript" src="js/bootstrap-datepicker.js"></script>
    <script type="text/javascript">
        var res = "";
        $(document).ready(function () {
            var date = Date();
            $(".datepicker").datepicker({
                autoClose: true,
                startDate: date,
                format: 'dd/mm/yyyy'
            });
        });
        function MainTypeChanged() {
            $('.msg').html("");
            var selected = $('#<%=rbMainType.ClientID %> input:checked').val();
            $('#<%=rbType.ClientID %> input:checked').prop('checked', false);
            if (selected == "1") {
                $('#divType').show();
                $('#divValue').hide();
            }
            else {
                $('#divValue').show();
                $("#divType").hide();
            }
            $('.lblHeading').html("Discount(Month)");
            $('.msg').html("Duration shouldn't be more than 4 Month.");

        }
        function TypeChanged() {
            $('.msg').html("");
            var selected = $('#<%=rbType.ClientID %> input:checked').val();
            $('#divValue').show();

            if (selected == "2") {
                $('.lblHeading').html("Discount(Rs)");
            }
            else {
                $('.lblHeading').html("Discount Rate(%)");
                $('.msg').html("Discount rate shouldn't exceed 50%.");
            }

          
        }
    </script>
</asp:Content>
